package com.smbms.controller;

import com.smbms.util.FileUtil;
import com.smbms.util.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 类名：ImgController
 * 作者：小涛
 * 创建时间：2021/8/27-15:35
 * 功能：
 */
@Controller
@RequestMapping("/img")
public class ImgController {
    @ResponseBody
    @RequestMapping("/upload")
    public Result upload(MultipartFile img, HttpSession session) throws IOException {
        String fileName = FileUtil.upload(img, session);
        if (fileName == null){
            return new Result(false,"文件上传失败");
        }
        return new Result(true, "上传文件成功", fileName);
    }
}
